package com.wwj.server.control;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

    public static void main(String[] args) {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

        Server server = applicationContext.getBean(Server.class);

        if (args.length < 2) {
            printParamInfo();
            System.exit(0);
            return;
        }

        try {
            String serverName = args[0];
            Integer port = Integer.parseInt(args[1]);
            server.start(serverName, port);
        } catch (NumberFormatException e) {
            printParamInfo();
            System.exit(0);
        }
    }

    private static void printParamInfo() {
        System.out.println("************************* 传入参数异常 *************************");
        System.out.println("* 参数: ServerName Port");
        System.out.println("**************************************************************");
        System.out.println("* ServerName            : 服务名称(唯一)");
        System.out.println("* Port                  : 服务占用端口号");
        System.out.println("**************************************************************");
    }

}
